#include <forward_list>
#include <iostream>

struct Session {
    int id;
    bool active;
};

int main() {
    std::forward_list<Session> sessions = {
        {1, true}, {2, false}, {3, true}, {4, false}, {5, true}
    };

    auto prev = sessions.before_begin();
    for (auto it = sessions.begin(); it != sessions.end(); ) {
        if (!it->active) {
            it = sessions.erase_after(prev); // 删除当前失效会话
        } else {
            prev = it;
            ++it;
        }
    }

    std::cout << "Active sessions:";
    for (const auto& s : sessions) {
        std::cout << ' ' << s.id;
    }
    std::cout << '\n';
    return 0;
}